package com.thyme.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author ah.caixiaodong@aisino.com
 * @ClassName TimeAspect
 * @Description TODO
 * @Date 2019/6/5 16:42
 */
@Aspect
@Component
public class TimeAspect {

    private static final Logger logger = LoggerFactory.getLogger(TimeAspect.class);

    @Around("execution(* com.thyme.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        logger.info("time aspect start");
        long start = System.currentTimeMillis();
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            logger.info("arg is " + arg);
        }
        Object proceed = pjp.proceed();
        logger.info("time aspect 耗时："+ (System.currentTimeMillis() - start));
        logger.info("time aspect end");
        return proceed;
    }
}
